//
//  TabBarViewController.swift
//  SwiftDemo
//
//  Created by 李文强 on 2017/1/10.
//  Copyright © 2017年 李文强. All rights reserved.
//

import Foundation
import UIKit

class TabBarViewController: UITabBarController {

    //写按钮
    lazy var vview:UIView = {
        let myW = Screen.width/5
        let myView = UIView()
        myView.frame = CGRect(x:Screen.width/2-myW/2,y:Screen.height-50,width:myW,height:50)
        myView.backgroundColor = UIColor.clear
        return myView
    }()
    lazy var composeButton:UIButton = {
        let myW = Screen.width/5
        let btn = UIButton()
        btn.frame = CGRect(x:myW/2-20,y:5,width:40,height:40)
        btn.setImage(UIImage(named:"圆角矩形 1.png"), for: UIControlState.normal)
        btn.backgroundColor = UIColor.white
        btn.setTitleColor(UIColor.white, for: UIControlState.normal)
        return btn
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let firstViewController = MainViewController();
        let navActuivityInfo = UINavigationController(rootViewController:firstViewController);
        navActuivityInfo.title = "First";
        navActuivityInfo.tabBarItem.image = UIImage(named: "Activity-information.png")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal);
        navActuivityInfo.tabBarItem.selectedImage = UIImage(named:"Activity-information_s.png")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal);
        
        
        let secondViewController = SecondViewController()
        let secondNav = UINavigationController(rootViewController:secondViewController)
        secondNav.title = "Secont"
        secondNav.tabBarItem.image = UIImage(named:"qq.png")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        secondNav.tabBarItem.selectedImage = UIImage(named:"")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        
        let thirdViewCOntroller = ThirdViewController()
        let thirdNav = UINavigationController(rootViewController:thirdViewCOntroller)
        thirdNav.title = "Third"
        thirdNav.tabBarItem.image = UIImage(named:"")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        thirdNav.tabBarItem.selectedImage = UIImage(named:"")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        
        let fourthVC  = FourthViewController()
        let forthNav = UINavigationController(rootViewController:fourthVC)
        forthNav.title = "Last"
        forthNav.tabBarItem.image = UIImage(named:"")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        forthNav.tabBarItem.selectedImage = UIImage(named:"")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        let nullC = ViewController()
        
        //添加
        let  itemsArray = [navActuivityInfo,secondNav,nullC,thirdNav,forthNav]
        self.viewControllers = itemsArray
        //自定义工具栏
//        self.tabBar.backgroundColor = UIColor.clear
//        self.tabBar.barTintColor = UIColor.blue
        
        //底部工具栏文字的颜色
        //7.设置底部工具栏文字颜色（默认状态和选中状态）
//        UITabBarItem.appearance().setTitleTextAttributes(NSDictionary(object:UIColor.white, forKey:NSForegroundColorAttributeName as NSCopying) as? [String : AnyObject], for:UIControlState.normal);
//        UITabBarItem.appearance().setTitleTextAttributes(NSDictionary(object:UIColor.blueWithTabbar(), for:NSForegroundColorAttributeName) as? [String : AnyObject], for:UIControlState.Selected)
        
        self.view.addSubview(self.vview)
        self.vview.addSubview(self.composeButton)
        self.composeButton.isSelected = false
        self.composeButton.addTarget(self, action: #selector(middleClick(button:)), for: UIControlEvents.touchUpInside)
        
        
        
        
        
        
        
        // Do any additional setup after loading the view.
    }
    func middleClick(button:UIButton) -> Void {
//        if button.isSelected == true {
//            button.isSelected = false
//        }else
//        {
//            button.isSelected = true
//        }
        let editVC = EditeViewController()
        //MARK:着这里设置会有半透明效果
        editVC.view.backgroundColor = UIColor.init(colorLiteralRed: 0.9098, green: 0.9098, blue: 0.9098, alpha: 0.9)
        self.modalPresentationStyle = .custom
        self.present(editVC, animated: true, completion: nil)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
